package com.cos66.adapters;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.cos66.R;
import com.cos66.Impl.OnDrawableReady;
import com.cos66.asynctask.ImagesAsyncTask;
import com.cos66.model.HotActivityItem;

public class HotActivityAdapter extends BaseAdapter {

	private Context context;
	private List<HotActivityItem> hotActivityData;
	ImagesAsyncTask imagesAsyncTask;
	
	public HotActivityAdapter(Context context,
			List<HotActivityItem> hotActivityData) {
		this.context = context;
		this.hotActivityData = hotActivityData;
	}

	public int getCount() {
		return hotActivityData.size();
	}

	public Object getItem(int position) {
		return hotActivityData.get(position);
	}

	public long getItemId(int position) {
		return hotActivityData.get(position).getHotActivityId();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView = new ImageView(context);
		imageView.setBackgroundResource(R.drawable.hot1);
		imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
		imageView.setLayoutParams(new Gallery.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		OnDrawableReady drawableReady = new OnDrawableReady(imageView);
		imagesAsyncTask = new ImagesAsyncTask();
		Drawable drawable = imagesAsyncTask.loadDrawable(hotActivityData.get(position)
				.getHotActivityImageUrl(), drawableReady);
		if(drawable!=null){
			imageView.setBackgroundDrawable(drawable);
		}
		return imageView;
	}

}
